import 'package:json_annotation/json_annotation.dart';

part 'platform_config.g.dart';

/// 平台配置枚举
enum TicketPlatform {
  @JsonValue('damai')
  damai,
  @JsonValue('maoyan')
  maoyan,
}

/// 平台配置类
@JsonSerializable()
class PlatformConfig {
  final TicketPlatform platform;
  final String name;
  final String baseUrl;
  final String appKey;
  final String version;
  final Map<String, String> headers;
  final Map<String, dynamic> apiEndpoints;
  final bool isEnabled;

  PlatformConfig({
    required this.platform,
    required this.name,
    required this.baseUrl,
    required this.appKey,
    required this.version,
    required this.headers,
    required this.apiEndpoints,
    this.isEnabled = true,
  });

  factory PlatformConfig.fromJson(Map<String, dynamic> json) => 
      _$PlatformConfigFromJson(json);
  Map<String, dynamic> toJson() => _$PlatformConfigToJson(this);

  /// 大麦网配置
  static PlatformConfig get damai => PlatformConfig(
    platform: TicketPlatform.damai,
    name: '大麦网',
    baseUrl: 'https://mtop.damai.cn',
    appKey: '12574478',
    version: '8.6.2',
    headers: {
      'Accept': 'application/json',
      'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
      'Accept-Encoding': 'gzip, deflate, br',
      'Connection': 'keep-alive',
      'Cache-Control': 'no-cache',
      'Pragma': 'no-cache',
    },
    apiEndpoints: {
      'orderBuild': '/h5/mtop.trade.order.build/4.0/',
      'orderCreate': '/h5/mtop.trade.order.create/4.0/',
      'itemDetail': '/h5/mtop.damai.item.detail/1.2/',
      'login': '/h5/mtop.user.login/1.0/',
      'search': '/h5/mtop.damai.search/1.0/',
    },
  );

  /// 猫眼电影配置
  static PlatformConfig get maoyan => PlatformConfig(
    platform: TicketPlatform.maoyan,
    name: '猫眼电影',
    baseUrl: 'https://m.maoyan.com',
    appKey: 'maoyan_app',
    version: '10.8.60',
    headers: {
      'Accept': 'application/json, text/plain, */*',
      'Accept-Language': 'zh-CN,zh;q=0.9',
      'Accept-Encoding': 'gzip, deflate, br',
      'Connection': 'keep-alive',
      'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MaoyanMovie/10.8.60',
    },
    apiEndpoints: {
      'orderBuild': '/ajax/order/build',
      'orderCreate': '/ajax/order/create',
      'movieDetail': '/ajax/movie/detail',
      'login': '/ajax/user/login',
      'search': '/ajax/search',
      'cinemaList': '/ajax/cinema/list',
      'showList': '/ajax/show/list',
    },
  );

  /// 获取所有支持的平台配置
  static List<PlatformConfig> get allPlatforms => [damai, maoyan];

  /// 根据平台类型获取配置
  static PlatformConfig getConfig(TicketPlatform platform) {
    switch (platform) {
      case TicketPlatform.damai:
        return damai;
      case TicketPlatform.maoyan:
        return maoyan;
    }
  }

  String get platformName {
    switch (platform) {
      case TicketPlatform.damai:
        return '大麦网';
      case TicketPlatform.maoyan:
        return '猫眼电影';
    }
  }

  String get platformIcon {
    switch (platform) {
      case TicketPlatform.damai:
        return '🎵';
      case TicketPlatform.maoyan:
        return '🎬';
    }
  }
}